<script>
    function subform(){
        $('#kform').submit();
    }
    
    function checkAll()
    {
        $('#table-select-all').attr('onclick','uncheckAll();');
    	var field=document.forms.kform;
        for (i = 0; i < field.length; i++)
    	field[i].checked = true ;
    }
    
    function uncheckAll()
    {
        $('#table-select-all').attr('onclick','checkAll();')
    	var field=document.forms.kform;
        for (i = 0; i < field.length; i++)
    	field[i].checked = false ;
    }
    
    $(function() {
                            $("#category").autocomplete("<?=$this->config->item('main_url').'/report/jsearchcategory/'?>", {
                        		width: 160,
                        		autoFill: true,
                        		selectFirst: true
                        	});

                            $("#supplier").autocomplete("<?=$this->config->item('main_url').'/report/jsearchsupplier/'?>", {
                                width: 160,
                                autoFill: true,
                                selectFirst: true
                            });
                            
})
                        
                        function generaltime(){
                            datestart = $('#datestart').val();
                            dateend = $('#dateend').val();
                            
                            datestart = new Date(datestart);
                            dateend = new Date(dateend);
                            
                            totaldate = ((dateend-datestart)/3600000).toFixed(2);
                            if(totaldate != NaN && totaldate > 0){
                                $('#key').val(totaldate);
                            }else{
                                $('#key').val('0');
                            }
                        }
                        
                /*$.validator.setDefaults({
                	submitHandler: function() { 
                        staff = $('#staff').val();                	   
                        datestart = $('#datestart').val();
                        dateend = $('#dateend').val();
                        salary = $('#salary').val();
                        
                        url = "<?=$this->config->item('main_url').'/report/print_paylist/?'?>";
                        window.open(url+"staff="+staff+"&datestart="+datestart+"&dateend="+dateend+"&salary="+salary,"myNewWinsr","width=620,height=800,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes"); 
                    }
                });   */ 
                $(document).ready(function() {
                        $("#kform").validate({
                    			rules: {
                    				/*bill_no: {
                    					required: true,
                    					minlength: 3,
                    					maxlength: 200
                    				},*/
                                    name: {
                    					required: true,					
                    				},
                    				staff: {
                    					required: true,					
                    				},
                                    datestart: {
                    					required: true,					
                    				},
                                    dateend: {
                    					required: true,					
                    				},
                                    key: {
                    					required: true,					
                    				}
                    			},
                    			messages: {
                    				/*bill_no: {
                    					required: "Please Enter Bill Number",
                                                            minlength: "Bill Number must consist of at least 3 characters"
                    				},*/
                                    name: {
                    					required: "Please Enter Title"					
                    				},
                    				staff: {
                    					required: "Please Enter Staff"
                    				},
                                    datestart: {
                    					required: "Please Enter Date start"				
                    				},
                                    dateend: {
                    					required: "Please Enter Date end"				
                    				},
                                    key: {
                    					required: "Please Enter Duration"					
                    				}
                    				
                    			}
                    		});
                      })
</script>